<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%-- 引入页面头 --%>
<%@ include file="/pageHead.jsp"%>
<form name="form1" id="form1" action="${systemctx}/sample/saveSample.web" method="post">
	<input type="hidden" id="id" name="id" >
	<div class="pageMain">
		<div class="pageTitle">
		<%=MessageResourcesUtils.getMessage(request, "systemmanage.storemanagement.title") %>
		<span></span>
		<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.title.channel") %>
		<span></span>
		<%=MessageResourcesUtils.getMessage(request, "dailyoperation.storeChannel.title.channel.list") %>
		</div>
		<div class="pageBody">
			<div class="form-group">
					<ul>
						<li>	
							<i></i>
							<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %></label>
							<span>
								<input type="text" id="storenumber" name="storenumber" value="" />
								<input type="hidden" id="storeid" name="storeid"  >		
							</span>
						</li>
						<li>
							<i></i>
							<label><%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %></label>
							<span><input type="text" id="storename" name="storename" value="" readonly="readonly" /></span>
						</li>
					</ul>					
			</div>	
		</div>
		<div class="button-group">
			<input type="button" class="btn btn-default" id="butQuery" name="butQuery" value="<%=MessageResourcesUtils.getMessage(request, "common.button.query") %>" />
			<input type="button" class="btn btn-default" onclick="addStoreChannel()" value="<%=MessageResourcesUtils.getMessage(request,"common.button.add")%>" />
			<input type="button" class="btn btn-default" onclick="exportfile()" value="<%=MessageResourcesUtils.getMessage(request,"common.button.exportsecret")%>" />
		</div>
		<table width="100%">
			<tbody>
				<tr>
					<td>
						<table id="datagrid"></table>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</form>
<script type="text/javascript">
	$(document).ready(function(){
		$('#datagrid').issdatagrid({
			formid : 'form1',
			title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.storeChannel.title.storechannel")%>',
			width : 'auto',
			nowrap : true,
			autoRowHeight : false,
			singleSelect : true,
			striped : true,
			url : '${systemctx}/dailyoperation/storechannel/queryStoreChannelListInfoDataGrid.json',
			sortName : 'modifytime',
			sortOrder : 'desc',
			remoteSort : true,
			idField : 'id',
			pagination : true,
			rownumbers : true,
			showFooter : true,
			queryParams:$('#form1').serializeObject(),
			columns : [[ 
				 {field:'ck', checkbox:true},
				 {		field : 'id',
						title : '<%=MessageResourcesUtils.getMessage(request, "common.button.operation") %>',
						width : 160,
						align : 'center',
						formatter : operate
				},
				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.storeChannel.column.url")%>',field : 'url',sortable : true,align : 'left'},
				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.storeChannel.column.storenumber")%>',field : 'storenumber',sortable : true,align : 'left',formatter:function(value,row,index){
				 return "<a href=\"javascript:void(0)\" onclick=\"view('"+row.id+"')\" >"+value+"</a>"
				}},
				{title : '<%=MessageResourcesUtils.getMessage(request,"dailyoperation.storeChannel.column.storename")%>',field : 'storename',sortable : true,align : 'left'}
	           ]],
			onLoadSuccess : function(data) {

			}
		});
		$('#butQuery').click(
			function() {
				$('#datagrid').datagrid('load',$('#form1').serializeObject());
		});
						
		function operate(val, row) {
			return '<a href="javascript:void(0);" class="easyui-linkbutton" onclick="channelModify('+ val + ')"><%=MessageResourcesUtils.getMessage(request, "common.button.update") %></a> '
				  +'<a href="javascript:void(0);" class="easyui-linkbutton" onclick="channelDelete('+ val + ')"><%=MessageResourcesUtils.getMessage(request, "common.button.delete") %></a> '
				  +'<a href="javascript:void(0);" class="easyui-linkbutton" onclick=common("' + row.url + '")><%=MessageResourcesUtils.getMessage(request, "common.button.common") %></a>'
		}
		selectCurrency();
	});
	
	function channelModify(id){
		$(this).isswindow({
			title : '<%=MessageResourcesUtils.getMessage(request, "systemmanage.User.add.title") %>',
			noheader : true,
			url : '${systemctx}/dailyoperation/storechannel/toUpdateChannel.web?id='+id
		});
	}
	function channelDelete(val) {
		var id = val;
		if (confirm("<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert2") %>")){
			//正在执行...
			showSending();
			$.ajax({
				type : 'GET',
				url : '${systemctx}/dailyoperation/storechannel/deleteChannel.json?id=' + id,
				dataType : 'json',
				success : function(data) {
					//关闭执行...
					closeSending();
					if(data.message == "<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.java.alert3") %>"){
						//显示AJAX请求后的提示信息
						$.fn.ajaxmessage(data);
						$('#datagrid').datagrid('reload',$('#form1').serializeObject());
						$('#datagrid').datagrid('clearSelections');
					}
				}
			});
		}
	}
	
	function addStoreChannel(){
		$(this).isswindow({
			noheader : true,
			url :"${systemctx}/dailyoperation/storechannel/toAddChannel.web"
		});
	}
	
	function exportfile(){
		var rows=$('#datagrid').datagrid("getChecked");
		if(rows.length<1){
			alert("<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert5") %>");
			return;
		}else if(rows.length!=1){
			alert("<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert5") %>");
			return;
		}
		
		$("#id").val(rows[0].id);
		if(confirm("<%=MessageResourcesUtils.getMessage(request, "alertinfo.common.jsp.alert4") %>")){
			form1.action="${systemctx}/dailyoperation/storechannel/exportSecretKey.web";
			form1.submit();
		}
	}
	
	function selectCurrency(){
		$("#storenumber").issNewMagnifier({
			title: '<%=MessageResourcesUtils.getMessage(request, "systemmanage.databasebinding.storemagnifiertitle") %>',
			url: '${systemctx}/publicMagnifier/publicMagnifier.json',
			sortName : 'modifytime',
			sortOrder : 'desc',
			linkName: 'number',
			callSqlKey: 'queryStoreMagnifierSql',
			changeIgnore: ['storenumber'],
			columns: [[
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.number") %>', field:'number', width:180, sortable:true, align: 'left', formel:'storenumber'},
					{title:'<%=MessageResourcesUtils.getMessage(request, "dailyoperation.store.column.name") %>', field:'name', sortable:true, align: 'left', formel:'storename'},
			       	{field:'id', hidden:true, formel:'storeid'}
			]],
			onBeforeOpen:function(p){
		      var queryParams = {
		    		  querystore: '%' + $('#storenumber').val() + '%',
		    		  statusid: <%=SysConstant.RecordStatus.VALID %>,
		    		  state : <%=SysConstant.CommonApproveStatus.OK %>
		      };
		      return queryParams;
		    }
		});
    }
	
	function view(id){
		$(this).isswindow({
			title : '',
			noheader : true,
			url : '${systemctx}/dailyoperation/storechannel/toViewChannel.web?id='+id
		});
	}
	
	function common(val) {
		showSending();
		$.ajax({
			type : 'POST',
			url : '${systemctx}/dailyoperation/storechannel/testCommonlist.json?url='+val,
			dataType : 'json',
			success : function(data) {
				closeSending();
		    	$.fn.ajaxmessage(data);
			}
		});
	}
</script>
<%-- 引入页面尾 --%>
<%@ include file="/pageFloor.jsp"%>